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,0,0,1,1,1,1,0|]; number=[|82,100,40,3,12,11,48,53,12,72,67,77,46,33,89,33,31,69,37,17| 67,90,53,77,35,42,68,14,56,48,21,85,6,74,37,27,7,17,21,60| 25,70,21,95,31,33,74,95,16,1,9,50,11,38,69,48,61,14,85,92| 6,51,48,88,77,44,40,12,35,27,76,7,96,29,81,93,22,26,97,66| 44,89,15,62,8,30,72,11,21,3,53,35,62,18,98,83,14,58,1,28| 98,85,81,26,5,25,32,4,83,83,22,41,58,37,31,19,84,2,84,26| 88,45,11,1,81,14,59,26,53,80,88,61,15,20,53,5,53,48,69,43| 95,97,93,36,86,2,85,64,82,42,83,38,21,86,15,64,1,21,65,89| 14,55,22,50,18,42,59,12,55,76,76,78,53,7,74,48,73,87,90,61| 94,19,24,69,92,64,73,84,44,5,42,61,2,46,70,15,59,45,15,64| 43,68,50,25,73,69,78,92,81,80,37,86,33,52,20,1,93,62,74,99| 81,13,56,17,36,1,52,61,75,8,54,32,34,64,37,17,51,23,68,64| 57,21,71,72,54,78,25,25,65,49,57,3,37,46,66,9,84,16,37,39| 81,60,94,33,59,92,71,69,35,61,56,12,94,62,86,94,37,15,49,86| 31,71,46,71,82,50,73,14,2,4,43,21,45,75,69,33,1,61,68,49| 54,24,71,69,69,12,92,16,38,33,19,74,67,34,81,59,38,59,67,50| 59,28,40,27,88,83,94,54,27,62,90,5,23,67,28,14,79,22,84,50| 70,19,75,3,61,85,19,75,44,88,82,27,42,68,79,29,40,64,38,31| 18,39,19,6,6,30,19,11,35,32,38,25,23,41,10,65,90,60,31,80| 89,1,45,33,87,20,97,80,23,8,16,12,8,17,54,66,16,6,60,8| 65,31,83,20,43,20,99,2,45,76,9,13,79,15,89,38,14,33,12,51| 68,97,96,70,12,70,75,20,15,65,80,70,82,90,94,63,54,91,66,76| 30,100,57,98,68,61,36,68,60,34,94,95,64,22,94,88,94,60,83,81| 53,33,89,44,13,29,67,66,66,74,87,62,5,16,68,12,95,87,25,94| 12,71,27,82,41,63,78,34,7,94,56,18,26,18,53,94,70,88,78,26| 73,5,55,88,79,92,13,77,17,25,8,72,6,40,81,66,53,80,65,60| 13,33,60,48,80,74,16,68,49,87,55,54,82,36,77,98,6,45,48,3| 4,60,25,43,31,54,42,86,68,86,86,35,30,84,79,2,81,11,8,31| 59,99,75,78,22,4,45,85,29,41,13,82,46,87,97,25,85,12,45,94| 68,72,61,77,89,6,7,97,8,16,43,30,98,79,65,46,35,96,67,24| 5,35,33,52,14,90,27,96,26,90,42,95,91,86,55,88,75,78,94,67| 57,65,48,61,8,63,70,19,79,80,4,11,75,56,46,75,33,33,3,76| 89,20,69,75,52,20,18,20,19,21,39,26,77,14,71,40,21,76,16,8| 33,77,62,54,96,57,43,22,37,65,29,71,63,15,79,72,87,87,52,39| 37,81,22,77,98,72,73,32,79,21,81,77,21,54,68,82,75,7,29,21| 52,53,94,3,46,6,39,74,80,14,40,35,93,49,7,1,66,26,68,16| 12,18,92,70,20,99,95,2,73,53,93,44,81,9,1,47,96,37,37,83| 100,45,47,39,39,33,79,96,13,84,18,24,63,7,93,16,57,48,36,10| 92,100,12,84,49,1,6,55,48,40,73,21,98,40,92,3,72,61,33,48| 17,39,3,68,96,76,45,62,40,54,100,83,26,94,5,48,90,10,77,4| 23,60,68,23,6,48,6,64,43,74,85,56,12,62,85,17,88,98,91,36| 29,51,46,79,50,73,49,28,98,35,39,80,23,96,89,45,12,92,44,73| 16,31,32,68,41,9,78,82,34,92,27,82,69,61,15,76,53,52,62,65| 8,24,95,57,34,92,56,92,49,52,67,98,76,8,57,53,4,56,9,27| 46,30,93,65,82,20,65,33,9,67,22,17,77,77,97,91,95,12,5,15| 36,89,29,91,85,98,24,58,14,59,26,100,52,69,54,96,82,46,38,63| 44,67,16,26,43,7,85,20,59,69,21,18,5,13,29,21,29,75,81,51| 33,91,58,66,64,12,84,35,61,9,61,89,97,87,85,16,96,80,80,2| 60,94,7,89,77,86,51,38,40,33,92,48,11,11,84,72,11,47,13,31| 25,28,6,90,92,43,51,61,39,15,53,8,20,67,47,32,50,19,27,13|]; p=17;